const app = getApp();

Page({
  data: {
    username:'',
    password:''
  },
  login: function() {
    wx.login({
      success: ()=> {
          wx.request({
            url: 'http://interview-api-t.itheima.net/h5/user/login',
            method: 'POST',
            data: {
              username:this.data.username,
              password:this.data.password
            },
            success: function(res) {

              console.log( res.data.data.token);
             wx.setStorageSync('liguangxia',res.data.data.token )
              wx.switchTab({
                url: '/pages/index1/index1',
              });
            },
            fail: function(error) {
              console.error('登录失败:', error);
            },
          });
      },
      fail: function(error) {
        console.error('wx.login()调用失败:', error);
      },
    });
  },
});
